import { Directive, ElementRef, Input, Renderer } from '@angular/core';
import { PermissionService } from '../../providers/permission.service';

@Directive({
    selector: '[permission]',
    providers: [PermissionService]
})
export class PermissionDirctive {
    @Input('permission') permissionCode: string; 

    constructor(
        private el: ElementRef, 
        private renderer: Renderer,
        private permissionService: PermissionService
    ) {}

    ngOnInit() {
        let hasPermission = this.permissionService.hasPermission(this.permissionCode);
        if (!hasPermission) {
            this.el.nativeElement.remove();
        }
    }
}
